<template>
  <view class="trainer-team">
    <view class="header">
      <text class="title">教练团队</text>
      <!-- <view class="view-all" @tap="navToAllTrainers">
        <text>查看全部</text>
      </view> -->
    </view>

    <scroll-view class="trainer-list" scroll-x enable-flex show-scrollbar="false" v-if="teacherList.length">
      <view class="trainer-item" v-for="(item, index) in teacherList" :key="index" @tap="handleTrainerClick(item)">
        <view class="avatar-wrapper">
          <image class="avatar" :src="item.avatar" />
        </view>
        <view class="name">{{ item.name }}</view>
        <view class="title">{{ item.info }}</view>
      </view>
    </scroll-view>
  </view>
</template>

<script setup>
import { ref } from 'vue'
import { useCommonStore } from '@/store';
const commonStore = useCommonStore();

defineProps({
  teacherList: Array
})

const trainerList = ref([
  {
    avatar: 'https://example.com/avatar1.jpg',
    name: '刘老师',
    title: '瑜伽大师01 PILATE S教练'
  },
  {
    avatar: 'https://example.com/avatar2.jpg',
    name: '刘老师',
    title: '瑜伽大师01 PILATE S教练'
  },
  // {
  //   avatar: 'https://example.com/avatar3.jpg',
  //   name: '刘老师',
  //   title: '瑜伽大师01 PILATE S教练'
  // },
  // {
  //   avatar: 'https://example.com/avatar4.jpg',
  //   name: '刘老师',
  //   title: '瑜伽大师01 PILATE S教练'
  // }
])

const navToAllTrainers = () => {
  uni.navigateTo({
    url: '/pages/trainers/index'
  })
}

const handleTrainerClick = (trainer) => {
  console.log('查看教练详情:', trainer)
  const { branchCode } = commonStore.storeAndCityInfo;
  uni.navigateTo({
    url: `/pages/subpackages/shopCenter/teacher-detail?teacherCode=${trainer.teacherCode}&branchCode=${branchCode}`
  })

}
</script>

<style lang="scss">
.trainer-team {

  .header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30rpx;
    padding: 30rpx 30rpx 0 30rpx;

    .title {
      font-size: 36rpx;
      font-weight: bold;
      color: #0F0F0F;
      position: relative;
    }

    .view-all {
      font-size: 24rpx;
      color: #666;
    }
  }

  .trainer-list {
    white-space: nowrap;
    padding: 10rpx 0;
    display: flex;

    .trainer-item {
      display: flex;
      flex-direction: column;
      align-items: center;
      margin-right: 30rpx;
      background: #fff;
      border-radius: 10rpx;
      padding: 12rpx 24rpx;
      box-sizing: border-box;

      &:last-child {
        margin-right: 0;
      }

      .avatar-wrapper {
        width: 156rpx;
        height: 156rpx;
        border-radius: 50%;
        overflow: hidden;
        margin-bottom: 16rpx;
        background: #f5f5f5;
      }

      .avatar {
        width: 156rpx;
        height: 156rpx;
      }

      .name {
        font-size: 20rpx;
        color: #343434;
        font-weight: bold;
        margin-bottom: 8rpx;
      }

      .title {
        font-size: 18rpx;
        color: #343434;
        text-align: center;
        white-space: normal;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
        width: 100%;
        text-align: left;
      }
    }
  }
}
</style>